package org.linuxgears.BouncingBall.model.context;

import java.awt.Rectangle;

import org.linuxgears.BouncingBall.model.Point;

public class BorderBounceTrigger implements Trigger<BallContext> {
	private Border border;

	public BorderBounceTrigger(Border border) {
		this.border = border;
	}

	@Override
	public boolean triggered(BallContext xtc) {
		Point position = xtc.getPosition();
		Rectangle bounds = xtc.getBounds();
		int size = xtc.getMovable().getSize();
		
		return  
        	( (position.getX() + size > bounds.width) && (border == Border.RIGHT) ) ||
        	( (position.getY() + size > bounds.height) && (border == Border.BOTTOM) ) ||
        	( (position.getX() < 0) && (border == Border.LEFT) ) ||
        	( (position.getY() < 0) && (border == Border.TOP) );
	}

}
